<?php 

Class pageController extends appController
{
	
	public function index()
	{
	
	
	
		
	
	}
	public function page()
	{
		
	
		$this->assign('parent_list',Model('menu')->get_parent_menu());
		$cat_id=intval($_GET['id']);
		$art_info=Model('page')->get_page_info($cat_id);
		if($art_info)
		{
			$this->assign('art',$art_info);
			$this->assign('action','update_page');
		}
		else 
		{
			$this->assign('action','new_page');
		}
		
		$this->assign('cat_id',$cat_id);
		
		$this->display('index.html');
		
	}
	
	public function update_page()
	{
		$cat_id=isset($_POST['cat_id'])?$_POST['cat_id']:'';
		$info['abstract']=isset($_POST['abstract'])?$_POST['abstract']:'';
		$info['keywords']=isset($_POST['keywords'])?$_POST['keywords']:'';
		$en_title=isset($_POST['en_title'])?$_POST['en_title']:'';
		$en_content=isset($_POST['en_content'])?$_POST['en_content']:'';
		$info['title']=isset($_POST['title'])?CH_SC.$_POST['title'].DIG_EC.EN_SC.$en_title.DIG_EC:'';
		$info['content']=isset($_POST['content'])?CH_SC.$_POST['content'].DIG_EC.EN_SC.$en_content.DIG_EC:'';
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['created']=isset($_POST['created'])?strtotime($_POST['created']):$_SERVER['REQUEST_TIME'];
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		$result=Model('page')->update_page($info,$cat_id);
		
		$data=array('error'=>0,'content'=>'','url'=>'');
		if($result)
		{
			$data['content']=Lang('SUCCESS_EDIT');
			$data['url']="index.php?g=admin&m=content&a=index";
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	}
     
	public function new_page()
	{
		$info['cat_id']=isset($_POST['cat_id'])?$_POST['cat_id']:'';
		$en_title=isset($_POST['en_title'])?$_POST['en_title']:'';
		$en_content=isset($_POST['en_content'])?$_POST['en_content']:'';
		$info['title']=isset($_POST['title'])?CH_SC.$_POST['title'].DIG_EC.EN_SC.$en_title.DIG_EC:'';
		$info['content']=isset($_POST['content'])?CH_SC.$_POST['content'].DIG_EC.EN_SC.$en_content.DIG_EC:'';
		$info['abstract']=isset($_POST['abstract'])?$_POST['abstract']:'';
		$info['keywords']=isset($_POST['keywords'])?$_POST['keywords']:'';
		
		
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['created']=$_SERVER['REQUEST_TIME'];
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		

		$data=array('error'=>0,'content'=>'','url'=>'');
		if(Model('page')->create_page($info))
		{
			$data['content']=Lang('SUCCESS_ADD');
			$data['url']="index.php?g=admin&m=content&a=index";
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	}
	
	public function file()
	{
		
		$file=current($_FILES);
		$result=array('error'=>0,'url'=>'');
		$thumb_url=Model('image')->upload_image($file,'page');
		$result['url']=$thumb_url;
		
		$result['message']='';
		print_r(json_encode($result));
		exit();
	}
	
	

	
	
}